<?php

namespace app\controllers;

use app\models\Project;
use app\models\User;
use Yii;
use yii\web\Controller;

class IndexController extends Controller
{
    public function actionIndex()
    {
        $gets = Yii::$app->request->get();
        $uid = Yii::$app->user->id;
        isset($gets['name']) && !empty($gets['name']) && $where['name'] = $gets['name'];
        isset($uid) && !empty($uid)&&$where['created_uid'] = $uid;

        $where['is_del'] = 0;
        $where['is_public'] = 1;

        $projects = Project::getAllProjects($where);
        if (!empty($projects['items'])){
            array_walk($projects['items'],function (&$v){
                $userInfo = User::findOne($v['created_uid']);
                $tipsArr = [
                    '创建时间：'.date('Y/m/d H:i',$v['created_time']),
                    '创建人：'.(isset($userInfo['username']) ? $userInfo['username'] : '匿名好汉'),
                    '是否公开：'.($v['is_public'] == '1' ? "是" : "否")
                ];

                $tips = implode('</br>',$tipsArr);

                $v['tips'] = $tips;
            });
        }
        return $this->render('index',compact('projects'));
    }
}
